package com.smartfarm.domain.handler;

import com.smartfarm.service.EquipmentManager;
import lombok.RequiredArgsConstructor;
//具体处理类检查紧急事件类型 低燃料事件（如 LOW_FUEL），
// 若匹配则处理，否则传递给下一个处理者。
@RequiredArgsConstructor
public class FuelEmergencyHandler extends EmergencyHandler {
    // 定义一个EquipmentManager类型的成员变量
    private final EquipmentManager equipmentManager;

    // 重写handleEmergency方法
    @Override
    public void handleEmergency(Emergency emergency) {
        // 判断紧急情况类型是否为低燃料
        if (emergency.getType() == Emergency.EmergencyType.LOW_FUEL) {
            // 处理低燃料紧急情况
            equipmentManager.updateEquipmentStatus(
                emergency.getEquipmentId(),
                equipmentManager.getEquipmentStatus(emergency.getEquipmentId())
                    .toBuilder()
                    .healthStatus("Needs Refuel")
                    .operationMode("Stopped")
                    .build()
            );
        } else {
            // 否则，将紧急情况传递给下一个处理器
            passToNextHandler(emergency);
        }
    }
} 